decorator-pattern 
└─ src 
├─ main 
│ └─ java 
│ └─ org.design.pattern.decorator 
│ └─ log 
│ ├─ Log.java // 定义日志接口或抽象类
│ ├─ Slf4jLog.java // 具体的日志实现类
│ └─ decorator 
│ ├─ LogDecorator.java // 抽象装饰者基类
│ ├─ MailLogDecorator.java // 发送邮件的通知方式
│ ├─ DingDingLogDecorator.java // 使用钉钉发送消息
│ └─ SMSLogDecorator.java // 短信通知
└─ test 
└─ java 
└─ org.design.pattern.decorator.test 
└─ LogTest.java // 测试代码文件

public interface Log {
    void write(String message);
}
public class Slf4jLog implements Log {
    @Override
    public void write(String message) {
        System.out.println(message);  // 这里简化处理直接打印到控制台.
    }
}
public abstract class LogDecorator implements Log {
    protected final Log decoratedLog;

    public LogDecorator(Log decoratedLog){
        this.decoratedLog = decoratedLog;
    }

    @Override
    public void write(String message){
        decoratedLog.write(message);
    }
}
// 添加邮件通知能力
public class MailLogDecorator extends LogDecorator {

    public MailLogDecorator(Log decoratedLog) {
        super(decoratedLog);
    }

    private void sendEmailNotification(){
        System.out.println("Sending email notification...");
    }

    @Override
    public void write(String message) {
        super.write(message);
        sendEmailNotification();
    }
}

// 类似地，还可以有其他的装饰者...
public class LogTest {
    public static void main(String[] args) {
        Log baseLogger = new Slf4jLog();  // 创建基础日志处理器

        // 动态地给baseLogger增加功能 (先加email再加sms)
        Log loggerWithAllNotifications =
            new SMSLogDecorator(new MailLogDecorator(baseLogger));

        // 写入一条信息并触发所有已注册的通知机制
        loggerWithAllNotifications.write("This is a decorated log entry.");
    }
}